package com.example.demo.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.rsocket.RSocketSecurity;
import org.springframework.security.rsocket.core.PayloadSocketAcceptorInterceptor;

@Configuration
public class RsConfig {

    @Bean
    public PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
        rsocket.authorizePayload(authorize -> {
                    authorize.setup().hasRole("SETUP")
                            .route("rsdemo*")
                            .hasRole("ADMIN")
                            .anyRequest()
                            .authenticated();
                }).jwt(Customizer.withDefaults());
        return rsocket.build();
    }
}
